package at.ac.tuwien.mg.wh.dto;

import java.io.Serializable;

import at.ac.tuwien.mg.wh.exception.WarehouseException;


public class ItemDTO implements Serializable{
	
	private static final long serialVersionUID = 2324077549833980564L;

	protected Long catalogId;
	protected Integer number;
	
	
	public ItemDTO(Long catalogId, Integer number) throws WarehouseException {
		super();
		if((number == null ) || number < 0){
			throw new WarehouseException("Number of items can not be negative: '"+number+"'");
		}
		this.catalogId = catalogId;
		this.number = number;
	}
	public ItemDTO() {

	}
	
	public String getName(){
		return resolveItem(catalogId);
	}

	public Long getCatalogId() {
		return catalogId;
	}


	public void setCatalogId(Long catalogId) {
		this.catalogId = catalogId;
	}


	public Integer getNumber() {
		return number;
	}


	public void setNumber(Integer number) throws WarehouseException {
		if(number < 0){
			throw new WarehouseException("Number of items can not be negative: '"+number+"'");
		}
		this.number = number;
	}
	@Override
	public String toString() {
		return ""+getName()+": "+number;
	}
	
	

	public static String resolveItem(Long l){
		
		if(l.equals(1L)){
			return "silver";
		}else if(l.equals(2L)){
			return "wood";
		}else if(l.equals(3L)){
			return "gold";
		}else if(l.equals(4L)){
			return "stone";
		}else{
			return "something else";
		}	
	}
	
	public static Long resolveItem(String str){
		
		if(str.equals("silver")){
			return 1L;
		}else if(str.equals("wood")){
			return 2L;
		}else if(str.equals("gold")){
			return 3L;
		}else if(str.equals("stone")){
			return 4L;
		}else{
			return 0L;
		}
	}

}
